<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>档案预览</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/admin/css/other/department.css"/>
    <link rel="stylesheet" href="/layer-css.css"/>
    <style>
        .centered {
            display: flex;
            flex-direction: row;
            align-items: center;
        }

        .separateInTheCenter {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
        }

        .pear-container {
            margin: 15px;
            width: calc(100vw - 30px);
        }

        body {
            font-family: Source Han Sans SC, Source Han Sans SC;
        }

        .searchCriteria .layui-form-label {
            width: 64px;
            font-size: 16px;
            color: #5A6878;
        }

        .searchCriteria button {
            line-height: 35px;
            font-size: 16px;
        }

        .searchCriteria .pear-btn-md {
            height: 38px;
        }

        .searchCriteria .layui-form-item .layui-inline {
            margin-bottom: 0px;
        }

        .searchCriteria .layui-icon {
            font-size: 15px;
        }

        .toolbarButton button {
            font-size: 16px;
            border: 0px;
            border-radius: 5px 5px 5px 5px;
        }

        .toolbarButton .layui-btn {
            margin-bottom: 0px;
        }

        .layui-table-box button {
            font-size: 14px !important;
            height: 25px;
            line-height: 23px;
        }

        #moreTools a {
            color: #1890FF;
            margin-left: 20px;
        }

        .layui-table-checked {
            background-color: #9e9e9e14;
        }

        .layui-table-checked.layui-table-hover {
            background-color: #9e9e9e14 !important;
        }

        .layui-btn-container .layui-btn {
            margin-left: 15px !important;
        }

        .organizationTree {
            width: 100% !important;
            height: -webkit-calc(100vh - 233px);
            height: -moz-calc(100vh - 233px);
            height: calc(100vh - 233px);
        }

        .layui-table-view {
            margin-top: 0px !important;
        }

        .layui-card-body .layui-form {
            margin-top: 12px;
        }

        .layui-form-item {
            margin-bottom: 12px;
        }

        .layui-breadcrumb a:hover {
            color: #2d8cf0 !important;
        }

        .searchCriteria .layui-form-item .layui-form-checkbox[lay-skin=primary] {
            margin-top: 0px;
        }

    </style>
</head>
<body class="pear-container">
<div class="layui-row layui-col-space15">
    <div class="layui-col-xs12 layui-col-md12">
        <div class="layui-card searchCriteria">
            <div class="layui-card-body">
                <span class="layui-breadcrumb" lay-separator=">">
                  <a th:href="${'/archives/index'}">档案</a>
                  <a><cite th:text="${archivesName} + '&nbsp;&nbsp;档案-子档案'"></cite></a>
                </span>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">图纸名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sonFileName" placeholder="请输入图纸名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-inline">
                                <input type="text" name="profile" placeholder="请输入备注" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="archive-query">
                                <i class="layui-icon layui-icon-search"></i>
                                查询
                            </button>
                            <button type="reset" class="pear-btn pear-btn-md">
                                <i class="layui-icon layui-icon-refresh"></i>
                                重置
                            </button>
                        </div>
                    </div>
            </div>
            </form>
        </div>
    </div>
</div>
</div>
<div class="layui-row layui-col-space15">
    <div class="layui-col-md12 layui-col-xs12">
        <div class="layui-card toolbarButton">
            <div class="layui-card-body" style="">
                <div class="layui-btn-container centered">
                    <button class="layui-btn layui-btn-primary layui-border-green"
                            style="background-color: rgb(57, 143, 255, 0.1);color: #398FFF !important;" lay-on="add">新增
                    </button>
                    <!--                    <button class="layui-btn layui-btn-primary layui-border-green"-->
                    <!--                            style="background-color: rgb(255,146,0, 0.1);color: #FF9200 !important; "-->
                    <!--                            lay-on="collection">收藏夹-->
                    <!--                    </button>-->
<!--                    <button class="layui-btn layui-btn-primary layui-border-green"-->
<!--                            style="background-color: rgb(57,143,255, 0.1);color: #398FFF !important;"-->
<!--                            lay-on="batchImport">批量导入-->
<!--                    </button>-->
                    <button class="layui-btn layui-btn-primary layui-border-green"
                            style="background-color: rgba(201,49,94,0.1);color: #d24c4c !important;"
                            lay-on="batchRemove">批量删除
                    </button>
                </div>
                <div style="min-width: 100%;margin-top: 12px;height: 40px;display: none;
                background: rgba(57, 143, 255, 0.12);border-radius: 4px 4px 4px 4px;
                border: 1px solid rgba(57, 143, 255, 0.5);" id="moreTools" class="centered">
                    <span style="margin-left: 30px;height: 25px">
                    <svg t="1725012638718" class="icon" viewBox="0 0 1024 1024" version="1.1"
                         xmlns="http://www.w3.org/2000/svg" p-id="1456" width="25" height="25">
                        <path d="M512 0a512 512 0 1 0 0 1024A512 512 0 0 0 512 0z m44.032 256v339.456a44.032 44.032 0 0 1-88.064 0V256a44.032 44.032 0 0 1 88.064 0zM512 684.032a64 64 0 1 1 0 128 64 64 0 0 1 0-128z"
                              fill="#2d8cf0" p-id="1457"></path>
                    </svg>
                    </span>
                    <span style="font-size: 16px;margin-left: 6px;">已选择&nbsp;&nbsp;
                        <span style="color: #2d8cf0" id="selectNumber">1</span>
                        &nbsp;&nbsp;项</span>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="layui-row layui-col-space15">
    <div class="layui-col-md12 layui-col-sm12">
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="archivesSubnameTable" lay-filter="archivesSubnameTable"></table>
            </div>
        </div>
    </div>
</div>
<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script th:inline="javascript">
    var archivesId = [[${archivesId}]];
    var curr = [[${curr}]];

    layui.use(['table', 'form', 'jquery', 'common', 'util'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        var util = layui.util;

        var addCollectionIdList = [];
        var fileNameList = "";

        //  新增、收藏夹、批量导入
        util.on({
            add: function () {
                parent.layer.open({
                    title: ['新增档案', 'font-size: 18px;'],
                    type: 2,
                    offset: 'r',
                    anim: 'slideLeft', // 从右往左
                    area: ['40%', '100%'],
                    shade: 0.5,
                    shadeClose: true,
                    maxmin: true,
                    move: false,
                    id: 'addNewEquipment',
                    content: '/archives/subname/insert/add?archivesId=' + archivesId,
                    end: function () {
                        table.reload('archivesSubnameTable');
                    }
                });
            },
            //收藏列表
            collection: function () {
                parent.layer.open({
                    title: ['收藏夹', 'font-size: 18px;'],
                    type: 2,
                    skin: 'layui-layer-radius', // 自定义一个CSS类名来设置边框圆角
                    area: ['70%', '80%'],
                    shade: 0.5,
                    shadeClose: true,
                    maxmin: true,
                    move: false,
                    id: 'collection',
                    content: '/archives/collection/table/view',
                    end: function () {
                        addCollectionIdList = [];
                    }
                });
            },
            //批量导入
            batchImport: function () {
                parent.layer.open({
                    title: ['批量导入', 'font-size: 18px;'],
                    type: 2,
                    skin: 'layui-layer-radius', // 自定义一个CSS类名来设置边框圆角
                    area: ['70%', '80%'],
                    shade: 0.5,
                    shadeClose: true,
                    maxmin: true,
                    move: false,
                    id: 'collection',
                    content: '/archives/preview/batchImport/view?archivesId=' + archivesId,
                    end: function () {
                        table.reload('archivesSubnameTable');
                    }
                });
            },
            // 添加收藏
            addCollection: function () {
                layer.confirm('确定要收藏吗?', {
                    icon: 3,
                    title: '提示',
                    shade: 0.5
                }, function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: '/archives/collection/add',
                        data: JSON.stringify({"addCollectionIdList": addCollectionIdList, "type": 2}),
                        dataType: 'json',
                        contentType: "application/json;charset=utf-8",
                        type: 'post',
                        success: function (result) {
                            layer.close(loading);
                            if (result.code === 200) {
                                layer.msg(result.message, {icon: 1, time: 1800}, function () {
                                    table.reload("archivesSubnameTable");
                                });
                            } else {
                                layer.msg(result.message, {icon: 2, time: 1800});
                            }
                        }
                    })
                });
            },
            // 批量删除
            batchRemove: function () {
                if (addCollectionIdList.length === 0) {
                    layer.msg("未选中数据", {
                        icon: 3,
                        time: 1000
                    });
                    return false;
                }
                layer.confirm('<div>确定要删除&nbsp;&nbsp;<span style="color: #FF9200;">' + fileNameList + '</span>&nbsp;&nbsp;档案吗?</div>', {
                    icon: 3,
                    title: ['提示', 'font-size: 18px;'],
                    shade: 0.5,
                    area: ['499px', '303px'],
                    id: "borrowingConfirm"
                }, function (index) {
                    layer.close(index);
                    $.ajax({
                        url: '/archives/subname/delete/view/' + addCollectionIdList,
                        dataType: 'json',
                        contentType: "application/json;charset=utf-8",
                        type: 'delete',
                        success: function (result) {
                            if (result.code === 200) {
                                layer.msg(result.message, {icon: 1, time: 1800}, function () {
                                    table.reload("archivesSubnameTable");
                                    $("#moreTools").css("display", "none")
                                });
                            } else {
                                layer.msg(result.message, {icon: 2, time: 1800});
                            }
                        }
                    })
                });
            }
        });

        let cols = [
            [{type: 'checkbox'},
                {title: '图纸名称', field: 'son_file_name', align: 'center'},
                {title: '图纸总数', field: 'drawing_count', align: 'center'},
                {title: '备注', field: 'profile', align: 'center'},
                {title: '创建时间', field: 'create_time', align: 'center'},
                // {title: '状态', field: 'status', align: 'center', templet: function (d) {
                //     return d.status === 0 ? '在库' : '出库';
                // }},
                {
                    title: '操作', align: 'center', width: 430, templet: function (d) {
                        let html = '';
                        // if (d.archives_book_id != archivesId) {
                        //     html += '<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="jumpToCurrentBook">跳转当前册</button>';
                        // }
                        html += '<button class="pear-btn  pear-btn-primary pear-btn-sm" lay-event="info"' +
                            '            style="background-color: #2DBBF0 !important;border: 1px solid #2DBBF0 !important;">详情' +
                            '    </button>' +
                            // '    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="transfer">转移</button>' +
                            '    <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit">修改</button>' +
                            '    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove">删除</button>';
                        return html;
                    }
                }
            ]
        ]

        tableIns = table.render({
            elem: '#archivesSubnameTable',
            url: '/archives/subname/list',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#user-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            where: {
                "archivesId": archivesId
            },
            id: 'archivesSubnameTable',
            //解决页码的问题
            done: function (res) {
                // 获得当前页码
                var brforeCurr = tableIns.config.page.curr;
                // 获得当前页的记录数
                var dataLength = table.cache['archivesSubnameTable'].length;
                var count = res.count; // 获得总记录数
                //如果当前页的记录数为0并且总记录数不为0
                if (dataLength == 0 && count != 0) {
                    // 刷新表格到上一页
                    table.reload("archivesSubnameTable", {
                        page: {
                            curr: brforeCurr - 1
                        }
                    });
                }
            },
            height: 'full-253',
        });

        // 复选框事件
        table.on('checkbox(archivesSubnameTable)', function (obj) {
            var id = obj.config.id;
            var checkStatus = table.checkStatus(id);
            var data = checkStatus.data;
            if (data.length > 0) {
                $("#selectNumber").text(data.length);
                $("#moreTools").css("display", "");
                addCollectionIdList = common.checkField(obj, 'archives_subname_id');
                fileNameList = common.checkField(obj, 'son_file_name');
            } else {
                $("#moreTools").css("display", "none")
            }

        });

        table.on('tool(archivesSubnameTable)', function (obj) {
            if (obj.event === 'borrowing') {
                window.borrowing(obj);
            } else if (obj.event === 'info') {
                window.info(obj);
            } else if (obj.event === 'transfer') {

            } else if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            } else if (obj.event === 'jumpToCurrentBook') {
                window.jumpToCurrentBook(obj);
            }
        });

        table.on('toolbar(archivesSubnameTable)', function (obj) {
            if (obj.event === 'refresh') {
                window.refresh();
            }
        });

        form.on('submit(archive-query)', function (data) {
            data.field.archivesId = archivesId;
            table.reload('archivesSubnameTable', {
                where: data.field
            })
            return false;
        });
        //借阅
        window.borrowing = function (obj) {
            layer.open({
                type: 2,
                title: ['借阅', 'font-size: 18px;'],
                shade: 0.5,
                maxmin: true, //开启最大化最小化按钮
                area: ['670px', '480px'],
                content: '/archives/preview/borrow/apply/view?archivesId=' + obj.data.id
            });
        }
        // 查看档案详情
        window.info = function (obj) {
            parent.layer.open({
                title: ['查看图纸详情', 'font-size: 18px;'],
                type: 2,
                offset: 'r',
                anim: 'slideLeft', // 从右往左
                area: ['40%', '100%'],
                shade: 0.5,
                shadeClose: true,
                maxmin: true,
                move: false,
                id: 'viewEquipment',
                content: '/archives/subname/view/' + obj.data.archives_subname_id,
            });
        }
        //修改图纸
        window.edit = function (obj) {
            parent.layer.open({
                title: ['修改图纸', 'font-size: 18px;'],
                type: 2,
                offset: 'r',
                anim: 'slideLeft', // 从右往左
                area: ['40%', '100%'],
                shade: 0.5,
                shadeClose: true,
                maxmin: true,
                move: false,
                id: 'addNewEquipment',
                content: '/archives/subname/update/edit/' + obj.data['archives_subname_id'],
                end: function () {
                    table.reload('archivesSubnameTable');
                }
            });
        }
        // 删除档案
        window.remove = function (obj) {
            layer.confirm('<div>确定要删除&nbsp;&nbsp;<span style="color: #FF9200;">' + obj.data.archives_file_name + '</span>&nbsp;&nbsp;档案吗?</div>', {
                icon: 3,
                title: ['提示', 'font-size: 18px;'],
                shade: 0.5,
                area: ['499px', '303px'],
                id: "borrowingConfirm"
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url: '/archives/subname/delete/view/' + obj.data['archives_subname_id'],
                    dataType: 'json',
                    contentType: "application/json;charset=utf-8",
                    type: 'delete',
                    success: function (result) {
                        if (result.code === 200) {
                            layer.msg(result.message, {icon: 1, time: 1800}, function () {
                                table.reload("archivesSubnameTable");
                            });
                        } else {
                            layer.msg(result.message, {icon: 2, time: 1800});
                        }
                    }
                })
            });
        }
        window.refresh = function (param) {
            table.reload('archivesSubnameTable');
        }

        window.jumpToCurrentBook = function (obj) {
            location.href = "/archives/preview/index?archivesId=" + obj.data.archives_book_id +
                "&archivesBookName=" + obj.data.archives_book_name + "&curr=" + curr;
        }
    })
</script>
</body>
</html>
